<?php

namespace App\Http\Requests\Admin;

use App\Http\Requests\Request;

class AdminUserStore extends Request
{
    public function rules()
    {
        return [
            'name' => 'required',
            'username' => 'required|unique:admin_users',
            'password' => [
                'required',
                function($attribute, $value, $fail) {
                    if (strlen($value) < 6) {
                        return $fail('密码长度不能小于6位');
                    }
                }
            ],
            'status' => 'required|boolean',
        ];
    }

    public function messages()
    {
        return [
            'name.required' => '用户昵称不能为空',
            'username.required' => '用户名不能为空',
            'username.unique' => '用户名已存在',
            'password' => '密码不能为空',
            'status.required' => '请选择帐户的启用状态',
            'status.boolean' => '帐户的启用状态错误',
        ];
    }
}
